package com.zy.explore.license.domain.mybatis.entity;


import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.explore.license.infrastructure.base.mybatis.MpBaseEntity;
import com.zy.explore.license.infrastructure.util.StrUtil;
import com.zy.explore.license.interfaces.frm.UserMsgFrm;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import javax.persistence.Id;
import java.util.Date;

/**
 * 用户消息表(表user_msg)ORM实体对象
 *
 * @author ZY
 * @date 2021-05-29 15:43:34
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("user_msg")
public class UserMsg extends MpBaseEntity<UserMsg, Long> {

    /**
     * 主键ID
     */
    @Id
    @TableId
    private Long id;

    /**
     * 用户ID
     */
    private Integer userId;

    /**
     * 站内信ID
     */
    private Long msgId;

    /**
     * 是否已读：0.否 1.是
     */
    private Integer readStatus;

    /**
     * 是否被删除：0.否 1.是
     */
    private Integer delFlag;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * Frm转Example条件查询对象
     *
     * @param frm 查询参数对象
     * @return 返回Example对象
     */
    public static QueryWrapper<UserMsg> getWrapper(UserMsgFrm frm) {
        if (frm.getPageNum() == null || frm.getPageNum() <= 0) {
            frm.setPageNum(1);
        }
        if (frm.getPageSize() == null || frm.getPageSize() <= 0) {
            frm.setPageSize(10);
        }
        QueryWrapper<UserMsg> wrapper = new QueryWrapper<>();
        if (frm.getId() != null) {
            wrapper.eq(StrUtil.fieldToColumn("id"), frm.getId());
        }
        if (frm.getUserId() != null) {
            wrapper.eq(StrUtil.fieldToColumn("userId"), frm.getUserId());
        }
        if (frm.getMsgId() != null) {
            wrapper.eq(StrUtil.fieldToColumn("msgId"), frm.getMsgId());
        }
        if (frm.getReadStatus() != null) {
            wrapper.eq(StrUtil.fieldToColumn("readStatus"), frm.getReadStatus());
        }
        if (frm.getDelFlag() != null) {
            wrapper.eq(StrUtil.fieldToColumn("delFlag"), frm.getDelFlag());
        }
        if (!StringUtils.isEmpty(frm.getCreateTimeBegin())) {
            wrapper.ge(StrUtil.fieldToColumn("createTime"), frm.getCreateTimeBegin());
        }
        if (!StringUtils.isEmpty(frm.getCreateTimeEnd())) {
            wrapper.le(StrUtil.fieldToColumn("createTime"), frm.getCreateTimeEnd());
        }
        if (!StringUtils.isEmpty(frm.getUpdateTimeBegin())) {
            wrapper.ge(StrUtil.fieldToColumn("updateTime"), frm.getUpdateTimeBegin());
        }
        if (!StringUtils.isEmpty(frm.getUpdateTimeEnd())) {
            wrapper.le(StrUtil.fieldToColumn("updateTime"), frm.getUpdateTimeEnd());
        }
        return wrapper;
    }

}